//
//  RootViewController.m
//  MoeFM
//
//  Created by miyang on 14-11-5.
//  Copyright (c) 2014年 StraightJet. All rights reserved.
//

#import "RootViewController.h"





@interface RootViewController ()

@end

@implementation RootViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        _scrollImg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"scrollBar.png"]];
        _scrollImg.frame = CGRectMake(0, 39, 140, 5);
        self.navigationController.navigationBar.translucent = NO;
        _findMusicVC = [[FindMusicTableViewController alloc] init];
        _myFMVC = [[MyFMTableViewController alloc] init];
        
        
        
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    UIView *titleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 280, 44)];
  
    UIButton *findMusicBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [findMusicBtn setTitle:@"发现音乐" forState:UIControlStateNormal];
    findMusicBtn.tag = 0;
    [findMusicBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    findMusicBtn.frame = CGRectMake(0, 0, 140, 44);
    [findMusicBtn addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    UIButton *myFMBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [myFMBtn setTitle:@"我的FM" forState:UIControlStateNormal];
    myFMBtn.tag = 1;
    [myFMBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    myFMBtn.frame = CGRectMake(140, 0, 140, 44);
    [myFMBtn addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];

    [titleView addSubview:_scrollImg];
    [titleView addSubview:findMusicBtn];
    [titleView addSubview:myFMBtn];
    
    self.navigationItem.titleView = titleView;
    
    
    [self.view addSubview:_findMusicVC.view];
    [self addChildViewController:_findMusicVC];
    [self addChildViewController:_myFMVC];
    
    
    
    UIToolbar *musicBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height-100, 320, 44)];
    musicBar.backgroundColor = [UIColor redColor];
    
    
}

- (void)buttonAction:(UIButton *)btn
{
    [UIView beginAnimations:@"scroll" context:nil];
    _scrollImg.frame = CGRectMake(btn.tag*140, 39, 140, 5);
    [UIView setAnimationDuration:0.5];
    [UIView commitAnimations];
    if (btn.tag == 1) {
        [self transitionFromViewController:_findMusicVC toViewController:_myFMVC duration:0 options:UIViewAnimationOptionAllowAnimatedContent animations:nil completion:nil];
        _myFMVC.view.frame = _findMusicVC.view.frame;
    }else if (btn.tag == 0)
    {
        [self transitionFromViewController:_myFMVC toViewController:_findMusicVC duration:0 options:UIViewAnimationOptionAllowAnimatedContent animations:nil completion:nil];
    }
    
    
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
